<script setup lang="ts">
import { ref, reactive, onMounted, computed } from 'vue'
import { useRouter } from 'vue-router'

defineOptions({
  name: 'PictureCard'
})

interface Props {
  picture: API.PictureVO;
  height?: number; // 高度
  width?: number | string; // 宽度
}

const props = withDefaults(defineProps<Props>(), {
  picture: {},
  height: 320,
  width: '100%'
})
const router = useRouter()

// 计算样式
const style = computed(() => {
  return {
    height: `${props.height}px`,
    width: isNaN(Number(props.width)) ? props.width : `${props.width}px`
  }
})

// 图片点击事件
const handleClick = () => {
  router.push({
    path: '/picture/detail',
    query: {
      id: props.picture.id
    }
  })
}
</script>

<template>
  <div class="picture-card" :style="style" @click="handleClick">
    <div class="picture-content">
      <img class="cover" :src="props.picture?.url" :alt="props.picture?.name" />
      <div class="footer">
        <div class="title">{{ props.picture?.name }}</div>
        <div class="description">{{ props.picture?.introduction }}</div>
        <a-tag v-for="tag in props.picture?.tags" :key="tag">{{ tag }}</a-tag>
      </div>
    </div>
  </div>
  <div class="recommend-tag">

  </div>
</template>

<style scoped lang="scss">
:deep(.ant-tag) {
  color: white;
}

.picture-card {
  width: 100%;
  height: 100%;
  position: relative;
}

.recommend-tag {
  position: absolute;
  top: -20px;
  left: -5px;
  width: 40px;
  height: 40px;
  background: url("@/assets/images/home/recommend-2.png");
  background-size: cover;
  //background-color: #ff4d4f;
  //color: #fff;
  //padding: 10px;
  //border-radius: 50%;
  //font-size: 15px;
  //font-weight: 500;
}

.picture-content {
  overflow: hidden;
  box-sizing: border-box;
  border-radius: 6px;
  width: 100%;
  height: 100%;

  position: relative;

  &::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    transition: all 0.4s ease-in-out;
    height: 45%;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0) 100%);
    opacity: 0;
  }
}

.picture-content:hover {
  // 底部线性渐变
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0) 100%);
  // 图片放大
  .cover {
    transform: scale(1.1);
  }

  // 底部文字显示
  .footer {
    bottom: 0;
  }
}

.picture-content:hover::after {
  opacity: 1;
}

.cover {
  height: 100%;
  width: 100%;
  object-fit: cover;
  cursor: pointer;
  transition: all 0.4s ease-in-out;
}

.footer {
  position: absolute;
  bottom: -200px;
  left: 0;
  right: 0;
  padding: 10px;
  cursor: pointer;
  color: white;
  transition: all 0.4s ease-in-out;
  height: fit-content;
  z-index: 999;

  div {
    margin: 10px 0;
  }

  .title {
    font-size: 18px;
    font-weight: bold;
  }
}
</style>
